<?php 
include "Includes/solotrn_sesion.php";
include "Includes/soloFun_Generales.php";
require_once "config.php";
require_once "Includes/conexion.class.php";

//'Entra cuando va a grabar
//'-----------------------------------------------------------------------------------------------------------------------------------------------
//'Response.Write(Request("opc"))
$CboSupervisor = $_REQUEST["CboSupervisor"]==""?0:$_REQUEST["CboSupervisor"];

if ($_REQUEST["hidId1"]!="") {
    $tabla = "solotb_nivel2";
    switch ($_REQUEST["opc"]) {
        case "M":
            $tipo = "UPDATE";
            $Combo=$_REQUEST["hidId1"];

//		      'Valida si no se ha modificado nada, regresa con OK
            if ($_REQUEST["TxtDesc"]==$_REQUEST["TxtDesc2"] && $CboSupervisor == $_REQUEST["CboSupervisor2"]) {
                header("location: trn_Categorias.php?SoloError=0&CmbModulo=$Combo");
            }

            $strSql="$tipo $tabla set ";
            $strSql .="id2=" . $_REQUEST["hidId2"] . ",";
            $strSql .="des='" . $_REQUEST["TxtDesc"] . "', ";
            $strSql .= "co_supervisor = $CboSupervisor ";
            $strSql .="where id1=" . $_REQUEST["hidId1"];
            $strSql .="  and id2=" . $_REQUEST["hidId3"];
//echo $CboSupervisor;
//echo $strSql;
            break;
        case "E":
            $tipo = "DELETE";
            $strSql= "$tipo from $tabla";
            $strSql .= " where id1=" . $_REQUEST["hidId1"];
            $strSql .= "  and id2=" . $_REQUEST["hidId2"];

            $Combo=$_REQUEST["hidId1"];
            break;
        default:
            $tipo = "INSERT";
            $strSql = "$tipo into $tabla values (";
            $strSql .= $_REQUEST["CmbModulo"] . ", ";
            $strSql .= $_REQUEST["hidId1"] . ",'";
            $strSql .= $_REQUEST["ATxtDesc"]  . "',";
            $strSql .= $CboSupervisor . ")";
            $Combo=$_REQUEST["CmbModulo"];

    }

    $arrQueries = array();
    array_push($arrQueries, $strSql);
    array_push($arrQueries, crearQueryLog($tabla, $tipo, $strSql));
    $oConexion = new Conexion($WORKFLOW["motor_base"], $WORKFLOW["db_usuario"], $WORKFLOW["db_password"],
            $WORKFLOW["basedatos"], $WORKFLOW["servidor"], $WORKFLOW["flags"], $WORKFLOW["encoding"]);
    //if(!$oConexion->EjecutarQuery($strSql)) {
    if(!$oConexion->EjecutarTransaccion($arrQueries)) {
        $strMsg="trn_Categorias.php?SoloError=1&CmbModulo=" . $Combo;
    } else {
        $strMsg="trn_Categorias.php?SoloError=0&CmbModulo="  . $Combo;
    }

    $oConexion->Cerrar();
    header("location: " . $strMsg);
}
//   end if
//'-----------------------------------------------------------------------------------------------------------------------------------------------
//'response.Write(Request("opc"))
//'response.End()
switch ($_REQUEST["opc"]) {
    case "M":
        $boton ="<input type='submit' name='CmdGrabar' value='Modificar' class='SoloStyle_Boton'>";
        $oculto="<input type='hidden' name='opc' value='M'>";
        $titulo="Modificaci&oacute;n de Departamento";
        break;
    case "E":
        $boton ="<input type='submit' name='CmdGrabar' value='Eliminar' class='SoloStyle_Boton'>";
        $oculto="<input type='hidden' name='opc' value='E'>";
        $titulo="Eliminaci&oacute;n de Departamento";
        break;
}

$strSql="select * from solotb_nivel1 where id1=" . $_REQUEST["id1"];

$oConexion = new Conexion($WORKFLOW["motor_base"], $WORKFLOW["db_usuario"], $WORKFLOW["db_password"], 
        $WORKFLOW["basedatos"], $WORKFLOW["servidor"], $WORKFLOW["flags"], $WORKFLOW["encoding"]);
if(!$oConexion->EjecutarQuery($strSql)) {


//      set Obj1=Server.CreateObject("ADODB.Recordset")
//      Obj1.Open strSql,session("SoloConn")

//   if err<>0 then
    $strERROR=1;
    $err=0;
}

$arrModu=$oConexion->getData("NUM");
$Desc=$arrModu[0][1];
$oConexion->Cerrar();

//Tecnicos
$soloSQL2 = "select nu_usua, no_usua from solotb_usuario where co_perf in (33,36)";
soloFun_ExecSQL ($soloSQL2,$SoloArrSupervisor);
//printArray($SoloArrSoporte);
$StrCboSupervisor = SoloFun_CargaCombo($SoloArrSupervisor,"CboSupervisor","",$CboSupervisor," style='width: 180px' class='SoloStyle_Texto' ", "B");
?>
<html>
    <head>
        <title>Documentacion</title>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
        <link rel="stylesheet" href="SoloStyles/Solostyles.css" type="text/css">
    </head>

    <body topmargin=0 leftmargin=0>
        <!-- Include File="includes/trn_header.asp" -->
        <p align="center" class="SoloStyle_TituloPaginas"><?php echo $titulo;?></p>

        <form name="frmIngreso" action="trn_GrabaCategoria.php" method="POST">


            <table border="0" width="70%" align="center">
                <tr>
                    <td class="SoloStyle_Etiqueta" width="20%"><b>Empresa</b></td>
                    <td class="SoloStyle_Texto"width="80%"><?php echo $Desc;?>
                        <input type="hidden" maxlenght="50" size="50" name="hidId1" class="SoloStyle_texto" value="<?php echo $_REQUEST["id1"];?>"></td>
                </tr>
                <tr>
                    <td class="SoloStyle_Etiqueta"><b>Transacci&oacute;n</b></td>
                    <td class="SoloStyle_Texto"><input type="hidden" maxlenght="50" size="50" name="hidId3" class="SoloStyle_texto" value="<?php echo $_REQUEST["id2"];?>">
                        <input type="text" maxlenght="50" size="35" name="hidId2" class="SoloStyle_texto" value="<?php echo $_REQUEST["id2"];?>"></td>
                </tr>
                <tr>
                    <td class="SoloStyle_Etiqueta">Departamento</td>
                    <td><input name="TxtDesc" type="text" class="SoloStyle_Texto" id="TxtDesc3" size="35" maxlenght="50" value="<?php echo $_REQUEST["ds1"];?>">
                        <input name="TxtDesc2" type="hidden" class="SoloStyle_Texto" id="TxtDesc2" size="50" maxlenght="50" value="<?php echo $_REQUEST["ds1"];?>"></td>
                </tr>
                <tr>
                    <td class="SoloStyle_Etiqueta">Supervisor</td>
                    <td><?php echo $StrCboSupervisor;?>
                    <input name="CboSupervisor2" type="hidden" class="SoloStyle_Texto" id="TxtDesc2" size="50" maxlenght="50" value="<?php echo $CboSupervisor;?>"></td>
                </tr>
            </table>

            <br><center><?php echo $boton;
echo $oculto;?></center>
        </form>

    </body>
</html>
